package com.cxf.windex.biz;

import com.cxf.windex.base.biz.BaseBiz;
import com.cxf.windex.base.util.DateUtil;
import com.cxf.windex.entity.JsType;
import com.cxf.windex.mapper.JsTypeMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @program: business_needs
 * @description: 类型表
 * @author: chenxf
 * @create: 2018-10-09 17:09
 **/
@Service
public class JsTypeBiz extends BaseBiz<JsTypeMapper, JsType> {

    /**
     * 类型列表
     *
     * @param limit 数量
     * @param offset 页码
     * @param orderStr  排序(升序或者降序)
     * @param code 类型代码
     * @param name 类型名称
     * @return
     */
    public List<JsType> list(int limit, int offset,  String orderStr,String code,String name) {
        Example example = new Example(JsType.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(code)) {
            criteria.andEqualTo("code",code);
        }
        if (StringUtils.isNotBlank(name)) {
            criteria.andLike("name", "%" + name + "%");
        }
        example.setOrderByClause("order_no " + orderStr);
        PageHelper.startPage(offset, limit);
        return selectByExample(example);
    }
    /**
     * 添加类型
     * @param entity
     */
    public void saveJsType(JsType entity){
        if(entity.getId()==null||entity.getId()==0){
            insertSelective(entity);
        }else{
            updateSelectiveById(entity);
        }
    }


}
